package org.springblade.modules.admin.controller;

import cn.hutool.core.convert.Convert;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.modules.admin.dto.MaintainLeaveUserPlanQuery;
import org.springblade.modules.admin.enums.MaintainLeaveCheckEnum;
import org.springblade.modules.admin.service.IBusinessApproveService;
import org.springblade.modules.admin.service.IMaintainPlanAffairService;
import org.springblade.modules.admin.service.IMaintainPlanCheckService;
import org.springblade.modules.admin.service.IMaintainPlanContentService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * @Description 维保离职业务
 * @Author ysq
 * @Date 2023/3/15
 **/
@RestController
@AllArgsConstructor
@RequestMapping("admin/maintain/leave")
@Api(value = "维保离职业务", tags = "维保离职业务接口")
public class MaintainLeaveController {

	private final IMaintainPlanContentService maintainPlanContentService;
	private final IBusinessApproveService businessApproveService;
	private final IMaintainPlanCheckService maintainPlanCheckService;
	private final IMaintainPlanAffairService maintainPlanAffairService;

	@GetMapping("/leave/check")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "离职业务校验")
	public R<Map<Integer, Object>> maintainLeaveCheck(@RequestParam Long leaveUserId) {
		TreeMap<Integer, Object> map = new TreeMap<>();
		map.put(MaintainLeaveCheckEnum.BY_PLAN.getId(), maintainPlanContentService.futureMaintainPlanStatistical(leaveUserId));
		map.put(MaintainLeaveCheckEnum.PJ_APPROVE.getId(), maintainPlanContentService.partApproveStatistical(leaveUserId));
		map.put(MaintainLeaveCheckEnum.MAL_APPROVE.getId(), businessApproveService.malfunctionApproveStatistical(leaveUserId));
		map.put(MaintainLeaveCheckEnum.DIMISSION.getId(), maintainPlanContentService.selectUserDimissionCount(leaveUserId));
		map.put(MaintainLeaveCheckEnum.SW_TASK.getId(), maintainPlanAffairService.getPlanUserList(Convert.toStr(leaveUserId)));
		map.put(MaintainLeaveCheckEnum.ZJ_TASK.getId(), maintainPlanCheckService.getPlanUserList(Convert.toStr(leaveUserId)));
		return R.data(map);
	}

	@PostMapping("/plan/status")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "离职业务获取关联任务状态")
	public R<List<Map<String,Object>>> maintainLeaveCheck(@RequestBody MaintainLeaveUserPlanQuery planQuery) {
		return R.data(maintainPlanContentService.selectLeaveUserPlanStatus(planQuery));
	}

}
